<%--
  Created by IntelliJ IDEA.
  User: Jamin
  Date: 2019/1/21
  Time: 16:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>${注册}</title>
    <link rel="stylesheet" href="../../css/bootstrap.css">
    <link rel="stylesheet" href="../../css/style.css">
    <script src="../../js/jquery.min.3.1.0.js"></script>
    <script src="../../css/bootstrap.css"></script>
    <script src="../../layuiadmin/layui/layui.all.js"></script>
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <header class="pay-header login">
        <a href="/${contextPath}" class="logo">
            <img src="../../images/logo2.png">
        </a>
    </header>
</head>


<body>
<main class="register">

    <form class="layui-form" action="" method="post" id="form">
        <table class="register-table">
            <tbody>
            <tr>
                <td colspan="2" class="register-tip">设置账号</td>
            </tr>
            <tr>
                <td class="left-col">账号</td>
                <td class="right-col"><input type="text" placeholder="设置你的账号" name="r_user_account" id="r_user_account"
                                             lay-verify="account">
                </td>
            </tr>
            <tr>
                <td colspan="2" class="register-tip">设置登录密码</td>
            </tr>
            <tr>
                <td class="left-col">登陆密码</td>
                <td class="right-col"><input type="password" placeholder="设置你的登陆密码" name="r_password" id="r_password"
                                             lay-verify="password">
                </td>
            </tr>
            <tr>
                <td class="left-col">密码确认</td>
                <td class="right-col"><input type="password" placeholder="请再次输入你的密码" id="repeatpassword"
                                             name="r_password" lay-verify="repeatpassword"></td>
            </tr>
            <tr>
                <td colspan="2" class="register-tip">设置手机号</td>
            </tr>
            <tr>
                <td class="left-col">手机号</td>
                <td class="right-col"><input name="r_phonenumber" placeholder="请输入你的手机号" id="r_phonenumber"
                                             lay-verify="phonenumber"></td>
            </tr>

            <tr>

                <td colspan="2" class="button-td">
                    <input type="hidden" name="refer" id="refer">
                    <button class="layui-btn" lay-submit="" lay-filter="register">提 交</button>
                </td>
            </tr>
            </tbody>
        </table>
    </form>
</main>
<footer class="footer-bottom">
    <div class="foot-content login">
        <div class="copyright" id="copyright">
            <div class="white-link login-text">
                <a>关于天猫</a>
                <a>帮助中心</a>
                <a>开放平台</a>
                <a> 诚聘英才</a>
                <a>联系我们</a>
                <a>网站合作</a>
                <a>法律声明</a>
                <a>知识产权</a>
                <a>廉正举报 </a>
            </div>
            <div class="white-link login-text">
                <a> 阿里巴巴集团</a><span class="slash">|</span>
                <a> 淘宝网</a><span class="slash">|</span>
                <a>天猫 </a><span class="slash">|</span>
                <a> 聚划算</a><span class="slash">|</span>
                <a>全球速卖通</a><span class="slash">|</span>
                <a>阿里巴巴国际交易市场</a><span class="slash">|</span>
                <a>1688</a><span class="slash">|</span>
                <a>阿里妈妈</a><span class="slash">|</span>
                <a> 阿里旅行·去啊 </a><span class="slash">|</span>
                <a> 阿里云计算 </a><span class="slash">|</span>
                <a> 友盟 </a><span class="slash">|</span>
                <a> 虾米 </a><span class="slash">|</span>
                <a> 天天动听 </a><span class="slash">|</span>
                <a> 来往 </a><span class="slash">|</span>
                <a> 钉钉 </a><span class="slash">|</span>
                <a> 支付宝 </a>
            </div>
            <div class="license">
                <span>增值电信业务经营许可证： <a>浙B2-20110446</a></span>
                <span>网络文化经营许可证：<a>浙网文[2015]0295-065号</a></span>
                <span><a>12318举报 </a></span><br>
                <span>互联网药品信息服务资质证书编号：<a>浙-（经营性）-2012-0005</a></span>
                <div class="copy-right-year">© 2003-2017 TMALL.COM 版权所有</div>

            </div>
        </div>
    </div>
</footer>


</body>
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit


        //自定义验证规则
        form.verify({
            account: function (value) {
                if (value.length==0) {
                    return '账号不得为空';
                }
            }
            , password: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            , phonenumber: [
                /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/
                , '请输入正确的手机号'
            ]
            ,repeatpassword:function (value) {
                if(value.length==0){
                    return '请确认密码'
                }
            }

        });


        //监听提交
        form.on('submit(register)', function (data) {

            if ($("#repeatpassword").val() != $("#r_password").val()) {
                alert("两次输入的密码不一致");
                return false;
            }


            $.ajax({
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "/RegisterServlet",//url
                data: $('#form').serialize(),
                success: function (data) {
                  if (data.status==1){
                      alert("注册成功");
                      window.location.href="Login.jsp";
                  }else {
                      alert("账号已被注册");
                      window.location.href="Register.jsp";
                  }


                }
            });


            return false;
        });


        var msg = "${msg}";
        if (msg !== "") {
            alert(msg);
        }
        $(function () {
            $("#refer").val(document.referrer);
            $("#form").submit(function () {
                if ($("#repeatpassword").val() != $("#r_password").val()) {
                    alert("两次输入的密码不一致");
                    return false;
                }
                if ($("#password").val() == "" || $("#account").val() == "") {
                    alert("账号或密码为空");
                    return false;
                }
                return true;
            });
        });});

</script>


</html>
